package game.targets.entity.world.arrow;

import com.badlogic.gdx.math.Quaternion;
import com.badlogic.gdx.physics.bullet.linearmath.btTransform;

public class ArrowDown extends ArrowState {

	private Quaternion quat;
	private btTransform tr;
	public static float TERMINAL_VELOCTY=70;
	public ArrowDown(Arrow pl) {
		super(pl);
	}

	@Override
	public void update(float delta) {
		float yVel=arrow.getBody().getLinearVelocity().y;
		float angle=Math.max(-90, yVel/TERMINAL_VELOCTY * 90);
		quat.idt();
		quat.setEulerAngles(0f, arrow.getSideAngle(), -angle);
		tr.setIdentity();
		tr.setRotation(quat);
		tr.setOrigin(arrow.getPosition());
		arrow.getBody().setWorldTransform(tr.inverse().inv());
	}

	@Override
	public void enter() {
		tr=new btTransform();
		quat=new Quaternion();
		tr.setIdentity();
		
	}

	@Override
	public void exit() {
		tr.dispose();
	}

}
